//
//  XYClassfySelectCell.swift
//  XYReadBook
//
//  Created by fox on 2017/9/7.
//  Copyright © 2017年 tsaievan. All rights reserved.
//

import UIKit

//
//  XWJReadcolumnViewCell.swift
//  BookRead
//
//  Created by fox on 2017/6/7.
//  Copyright © 2017年 DZM. All rights reserved.
//

import UIKit


/// 阅读分类的 tableViewCell
class XYClassfySelectCell: UITableViewCell {
    
    var model:BookModel? {
        didSet {
            if let model = model {
            titleBookName.text = model.title
            userName.text      = model.author
            bookText.text      = model.shortIntro // male_11
            let imageUrl = BaseUrl.image.rawValue.appending(model.cover)//cover_default
            imageViewIcon.setImageView(urlString: imageUrl, placeHolder: "Image_loading")
            id = model.id
            if model.majorCate != "" || model.minorCate != "" {
                tagsTitle.text = String.init(format: " |  %@ %@", model.minorCate,model.majorCate)
            }
          
               var count:Double = Double(Int(arc4random()%20000)+2000)
               count = model.latelyFollower + count
            readCountlab.text = String.init(format: "%.1f万人在读", count/10000)
        }
    }
}
    /// 默认是false
    public var isSelect = false
    
    var textString = ""
    public var id = ""
    var arr = [""]
    var imageViewIcon = UIImageView() // icon
    var titleBookName = UILabel() //书籍名字
    
    var userName = UILabel() // 用户名字
    var bookText = UILabel()// 书籍内容
    var tagsTitle = UILabel()//tags
    var readCountlab = UILabel()
    var lineView = UIView()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setupUI()
    }
    
    
    func setupUI(){
        titleBookName.font = UIFont.boldSystemFont(ofSize: 17)
        userName.font = UIFont.systemFont(ofSize: 12)
        bookText.numberOfLines = 1
        bookText.font = UIFont.boldSystemFont(ofSize: 12)
        tagsTitle.font = UIFont.boldSystemFont(ofSize: 12)
        
        contentView.addSubview(imageViewIcon)
        contentView.addSubview(titleBookName)
        
        contentView.addSubview(userName)
        contentView.addSubview(bookText)
        contentView.addSubview(tagsTitle)
        contentView.addSubview(readCountlab)
        readCountlab.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(lineView)
        lineView.backgroundColor = UIColor.init(red: 239/255.0, green: 239/255.0, blue: 239/255.0, alpha: 1)
        tagsTitle.textAlignment = .right
        imageViewIcon.image = UIImage.init(named: "Image_loading")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        
        imageViewIcon.frame = CGRect.init(x: 12, y: 8, width: 60, height: 86)
        titleBookName.frame = CGRect.init(x: 96, y: 10, width: ScreenWidth - 90, height: 24)
        userName.frame = CGRect.init(x: 96, y: Int(titleBookName.frame.maxY + 4), width: Int(0), height: 14)
       
        userName.sizeToFit()
        tagsTitle.frame = CGRect.init(x: userName.frame.maxX, y: userName.y, width: 0, height:14)
        tagsTitle.sizeToFit()
        bookText.frame = CGRect.init(x: 96, y: userName.frame.maxY + 4, width: self.width - 104, height: 20)
        readCountlab.frame = CGRect.init(x: bookText.x, y: bookText.frame.maxY, width:200, height: 20)
        lineView.frame = CGRect.init(x: 0, y: self.height - 1, width: self.width, height: 1)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        
    }  
}

